home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Documentation / Development Notes / Converting from d11 / Conversion from d11 (2) < prev    next >
Encoding:
Text File  |  1996-04-26  |  10.4 KB  |  270 lines  |  [TEXT/ttxt]

  1. OpenDoc
  2. Development
  3. Framework
  4. __________________________________________________________________________________________
  5. Converting from d11 - part II 
  6. ODF Release 1                                                                                                                                                                          
  7.  
  8.  
  9.  
  10. Table of Contents
  11.  
  12. • Auto-destruct objects
  13. • Collections
  14. • Exception Handling
  15. • Macros
  16. • SOMnification and Shared Library
  17. • Storage Units and Archiving
  18.      • Writing to a StorageUnit
  19.      • Registering with the Archiver
  20. • Strings
  21.      • Archiving Strings
  22.  
  23.  
  24. Auto-destruct objects
  25.  
  26. The way in which you define auto-destruct classes has changed.  The new way to make a class be an autodestruct object is to use the FW_DECLARE_AUTO(className) macro in the class definition, and the FW_DEFINE_AUTO(className) macro in the .cpp file that contains the constructors and destructor for the class.  These macros are similar to the FW_DECLARE_CLASS and FW_DEFINE_CLASS macros used for RTTI, with the difference that FW_DECLARE_AUTO requires the class name parameter.
  27.  
  28. Old way:
  29.    class CFoo FW_AUTO_DESTRUCT_OBJECT
  30.    {
  31.       public:
  32.       ...                                            
  33.    };
  34.  
  35. New way:
  36.    class CFoo
  37.    {
  38.       public:
  39.          FW_DECLARE_AUTO(CFoo)
  40.       ...
  41.    };
  42.  
  43. The FW_DEFINE_AUTO macro should be added to the .cpp file before the first constructor:
  44. FW_DEFINE_AUTO(CFoo)
  45. // CFoo constructor follows
  46.  
  47. If you subclass an auto-destruct class, you must add the two macros to your derived class. If you forget them you’ll get cryptic link errors when you build. The following ODF classes are all auto-destruct classes:
  48.       FW_CPart
  49.       FW_CFrame
  50.       FW_CSelection
  51.       FW_CCommand
  52.       FW_CContent
  53.       FW_CDialogFrame, FW_CAboutFrame
  54.       FW_CFacetClipper
  55.       FW_CGraphicContext
  56.       FW_CIdler
  57.       FW_CLinkManager
  58.       FW_CPrintJob
  59.       FW_CReadableStream, FW_CWriteableStream
  60.       FW_CScroller
  61.       FW_CSemanticInterface
  62.       FW_MScriptable
  63.       FW_TOrderedCollection, FW_TOrderedCollectionIterator
  64.       many view subclasses: FW_CButton, FW_CEditView, FW_CListBox, FW_CStaticText, etc.
  65.  
  66. Remember that you must use FW_NEW instead of new to instantiate an auto-destruct class. 
  67.  
  68. Auto-destruct objects may now inherit from more than one auto-destruct base class.  Note that auto-destruct objects no longer need have a virtual destructor, so they may be lightweight objects without vtables.
  69.  
  70. See “Using Auto-Destruct Classes” in chapter 9 of the ODF Developer’s Guide for details on auto-destruct classes and how to use them.
  71.  
  72.  
  73. Collections
  74.  
  75. Collections and their iterators are now template-based.
  76.  
  77. • Old way to iterate elements of a collection:
  78.    FW_CPrivOrderedCollection* xxxList;
  79.  
  80.    FW_COrderedCollectionIterator it(xxxList);
  81.    for (CXxx* theXxx = (CXxx*)it.First(); it.IsNotComplete(); theXxx = (CXxx*)it.Next())
  82.  
  83. • New  way:
  84.    CXxxCollection* xxxList;
  85.  
  86.    CXxxCollectionIterator ite(xxxList);
  87.    for (CXxx* theXxx = it.First(); it.IsNotComplete(); theXxx = it.Next())
  88.  
  89. • Here is a “template” (pun intended) for a collection class definition (in .h file):
  90. class CXxxCollection : public FW_TOrderedCollection<CXxx>
  91. {
  92. public:
  93.       FW_DECLARE_AUTO(CXxxCollection)
  94.     
  95.       CXxxCollection() :
  96.             FW_TOrderedCollection<CXxx>(){}
  97.       ~CXxxCollection() {}
  98. };
  99.  
  100. • Here is a “template” for an iterator class definition (in .h file):
  101. class CXxxCollectionIterator : public FW_TOrderedCollectionIterator<CXxx>
  102. {
  103. public:
  104.       FW_DECLARE_AUTO(CXxxCollectionIterator)
  105.     
  106.       CXxxCollectionIterator(CXxxCollection* collection) :
  107.             FW_TOrderedCollectionIterator<CXxx>(collection){}
  108.       ~CXxxCollectionIterator() {}
  109. };
  110.  
  111. • In your .cpp file you should force the template classes to be instantiated like this:
  112. FW_DEFINE_AUTO(CXxxCollection)
  113. FW_DEFINE_AUTO(CXxxCollectionIterator)
  114.  
  115.  
  116. Exception Handling
  117.  
  118. Exception objects are no longer derived from an implementation base class. The FW_EXCEPTION_OBJECT macro is no longer used and is intentionally undefined. However, any users who defined their own base exception classes will probably not need to make any changes other than removing the use of the FW_EXCEPTION_OBJECT, and possibly using FW_DECLARE_EXCEPTION and FW_DEFINE_EXCEPTION.
  119.  
  120. See the Engineering Note “Exceptions/RTTI” for more information.
  121.  
  122.  
  123. Macros
  124.  
  125. A number of macros have become obsolete.
  126.  
  127. • FW_AUTO_DESTRUCT_OBJECT and FW_AUTO_DESTRUCT_MIXIN (see “Auto-destruct objects”, above)
  128.  
  129. • Remove all FW_CLASS_ATTR and FW_FUNC_ATTR macros.
  130.  
  131. • FW_EXCEPTION_OBJECT (see “Exception Handling”, above)
  132.  
  133. • Remove all FW_LIB_EXPORT_PRAGMAS.
  134.  
  135. Old style (from DrawFrm.h in the Draw sample):
  136. #if FW_LIB_EXPORT_PRAGMAS
  137. #pragma import on
  138. #endif
  139. class FW_CLASS_ATTR FW_CPresentation;
  140. class FW_CLASS_ATTR FW_CGrowBox;
  141. #if FW_LIB_EXPORT_PRAGMAS
  142. #pragma import off
  143. #endif
  144.  
  145. class FW_CLASS_ATTR CDrawPart;
  146. class FW_CLASS_ATTR CDrawSelection;
  147. class FW_CLASS_ATTR FW_CRuler;
  148.  
  149. New style:
  150. class FW_CPresentation;
  151. class FW_CGrowBox;
  152. class CDrawPart;
  153. class CDrawSelection;
  154. class CRuler;
  155.  
  156. I think it looks a lot better, don’t you?
  157.  
  158.  
  159. SOMnification and Shared Library
  160.  
  161. A number of classes in the Foundation and OS layers were converted to SOM classes. In addition, much of the code in the Foundation and OS layers was moved to the ODF shared library. Not to worry, ODF provides wrapper classes that you can use in ODF 1. Here is a list of those classes and the name of the class to use instead:
  162.  
  163.     FW_CRandomAccessSink           FW_PRandomAccessSink
  164.     FW_CMemorySink                    FW_PMemorySink
  165.     FW_CDirectorySpecification     FW_PDirectorySpecification
  166.     FW_CFileRep                          FW_PFile
  167.     FW_CFileSink                         FW_PFileSink
  168.     FW_CFileSpecification          FW_PFileSpecification
  169.     FW_CResource                         FW_PResource
  170.     FW_CResourceFile                     FW_PResourceFile    
  171.     FW_CResourceSink                     FW_PResourceSink
  172.  FW_CShapeListRep            FW_PShapeList
  173.     FW_CStorageUnitSink            FW_PStorageUnitSink
  174.  
  175. See the document “ODF Shared Library” for an explanation of wrapper classes and the shared library.
  176.  
  177. An Environment* argument has been added to most of the constructors for these classes. For example, compare this fragment from CScriptAction::InternalizeScriptFile in the Button part:
  178.    // Make the file specification
  179.    FW_CFileSpecification fileSpec(hfsInfo.fileSpec);
  180.         
  181.    // Acquire an opened resource file, 
  182.    // will be closed automatically
  183.    FW_CResourceFile resourceFile(fileSpec);
  184.         
  185.    // Acquire an opened resource, 
  186.    // will be released automatically
  187.    FW_CResource resource(resourceFile, 128, 'scpt');
  188.    FW_CAcquireResourceData lockedResource(resource);
  189.  
  190. Here is the ODF 1 version: 
  191.    // Make the file specification
  192.    FW_PFileSpecification fileSpec(ev, hfsInfo.fileSpec);
  193.         
  194.    // Acquire an opened resource file, 
  195.    // will be closed automatically
  196.    FW_PResourceFile resourceFile(ev, fileSpec);
  197.         
  198.    // Acquire an opened resource, 
  199.    // will be released automatically
  200.    FW_PResource resource(ev, resourceFile, 128, 'scpt');
  201.    FW_CAcquireResourceData lockedResource(ev, resource);
  202.  
  203. • ODF 1 provides a more efficient mechanism to access the Environment variable when there is no ev parameter. Instead of calling somGetGlobalEnvironment, you can use the class FW_SOMEnvironment to declare an ev on the stack. Simply replace this line:
  204.    Environment* ev = somGetGlobalEnvironment();
  205. with this line: 
  206.    FW_SOMEnvironment ev;
  207.  
  208.  
  209. Storage Units and Archiving
  210.  
  211. There are some picky little API changes in the storage unit streaming classes. For example, the name of FW_CStorageUnitSink has been changed to FW_PStorageUnitSink. Environment variables have been added in a few places, too.
  212.  
  213. Writing to a StorageUnit
  214.  
  215. Old way to write a proxy (in CMyPart::ExternalizeContent):
  216.    FW_CStorageUnitSink suSink(storageUnit, kODPropContents, CMyPart::kPartKind);
  217.    FW_CWritableStream archive(&suSink);
  218.    proxy->Externalize(ev, suSink.GetStorageUnitView(), cloneInfo);
  219.  
  220. New  way (in CMyContent::Externalize):
  221.    FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fPart->GetPartKind(ev));
  222.    FW_CWritableStream archive(suSink);
  223.    proxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  224.  
  225. Registering with the Archiver
  226. The archiver and all archiving functions were changed to provide better support for view editors.  Now, all archiving functions take an extra argument which is the "type constant" identifying the class of the object being created from the stream. This makes it possible to write one set of four "wild card" archiving functions that could be used with many classes.
  227.  
  228. The four archiving functions now have the following prototypes:
  229.     
  230. typedef void* (*Create)(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  231. typedef void (*Initialize)(FW_CReadableStream& stream, FW_ClassTypeConstant type, void* object);
  232. typedef void (*Destroy)(void* object, FW_ClassTypeConstant type);
  233. typedef void (*Output)(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  234.  
  235. Here is an example from ODFDraw:
  236. const FW_ClassTypeConstant LBaseShape = FW_TYPE_CONSTANT('s','h','b','a');
  237. FW_REGISTER_ARCHIVABLE_CLASS(LBaseShape, CBaseShape, CBaseShape::Read, 0, 0, CBaseShape::Write)
  238.  
  239. Note that the FW_REGISTER_ARCHIVABLE_CLASS macro has two additional parameters, for the initialize and destroy functions.
  240.  
  241. See the chapter on Streams in the ODF Class Reference for more information.
  242.  
  243.  
  244. Strings
  245.  
  246. The string classes have been re-org’ed and moved to the ODF shared library. The string class hierarchy has been simplified; the classes FW_CByteString, FW_CDynamicString, and FW_CIntlString are gone. Simply use FW_CString for everything. If you want to use a bounded string, FW_CString32 and FW_CString255 are still available. 
  247.  
  248. The operator const char*() was removed, so in order to get a C (null-terminated) string from an FW_CString it is now necessary to explicitly export one using the method ExportCString.
  249.  
  250. Archiving Strings
  251. The special classes for archiving strings (FW_CStringArchiver, FW_CDynamicStringArchiver, etc.) have all been removed. To read a string, simply stream it from an FW_CReadableStream:
  252.  
  253. void CSomeObject::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  254. {
  255.      FW_CString label;
  256.      stream >> label;
  257. }
  258.  
  259. To archive a string, stream it to an FW_CWritableStream:
  260.  
  261. void CSomeObject::Archive(Environment* ev, FW_CWritableStream& stream)
  262. {
  263.      FW_CString label(fDescription);
  264.      stream << label;
  265. }
  266.  
  267. See the Engineering Note “Strings” for more information.
  268.  
  269. © 1993 - 1996 Apple Computer, Inc. All rights reserved.
  270. Apple, the Apple Logo, Macintosh, and OpenDoc are trademarks of Apple Computer, Inc., registered in the United States and other countries.